import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/automounting_provider.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';

class AutoMountingType extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return AutoMountingTypeState();
  }

}

class AutoMountingTypeState extends State<AutoMountingType>{
  List backgroundList = [ "assets/images/auto_mounting_bg1.png", "assets/images/auto_mounting_bg2.png","assets/images/auto_mounting_bg3.png","assets/images/auto_mounting_bg4.png"];
  @override
  void initState(){
    super.initState();
//    WidgetsBinding.instance.addPostFrameCallback((_){
//
//    });
  }
  List<Widget> getGridViews(){
    List details=Provider.of<AutoMountingProvider>(context).detailListData;
    List<Widget> gridViews=new List();
    for(int i=0;i<details.length;i++){
      gridViews.add(
        GestureDetector(
          child: Container(
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(backgroundList[i]),
                    fit: BoxFit.fill)
            ),
            alignment: Alignment.center,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("${details[i]['inPutawaytypename']}"),
                Text("${details[i]['inautoputawayList'].length}",style: TextStyle(color: Colors.black,fontSize: 38),)
              ],
            ),
          ),
          onTap: (){
            Provider.of<AutoMountingProvider>(context).setInPutawaytypename(details[i]['inPutawaytypename']);
            Provider.of<AutoMountingProvider>(context).setInautoputawayList(details[i]['inautoputawayList']);
            Navigator.pushNamed(context, "/automounting_detail_list");
          },
        ),
      );
    }
    return gridViews;
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "上架类型选择",
          style: TextStyle(fontSize: 18),
        ),
        elevation: 0,
        centerTitle: true,
      ),
      body:  LoadBuilder(
    visibility: Provider.of<AutoMountingProvider>(context).netStatus2,
    builder:GridView(
        padding: EdgeInsets.only(left: 12,right: 12,top: 12),
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2, //横轴三个子widget
          childAspectRatio: 3/5, //宽高比为1时，子widget
          crossAxisSpacing: 12.0,
          mainAxisSpacing: 12.0,
        ),
        children: getGridViews()
    )),

    );
  }
}